package com.baselibrary.utils

import android.app.Activity
import android.view.ViewGroup

/**
 *@author:hanke
 *2023/4/25
 *desc:
 */
object MarginUtils {
    //动态设置控件距离顶部的距离，包含StatusBar高度
    fun setViewGroupMarginTopIncludeStatusBar(activity: Activity, viewGroup: ViewGroup, height: Int) {
        val params = viewGroup.layoutParams
        //获取view的margin设置参数
        var marginParams: ViewGroup.MarginLayoutParams? = if (params is ViewGroup.MarginLayoutParams) {
            params
        } else {
            ViewGroup.MarginLayoutParams(params)
        }
        marginParams?.setMargins(ScreenUtils.dpToPx(0), ScreenUtils.dpToPx(height) + StatusBarUtil.getStatusBarHeight(activity), 0, 0)
    }

    fun setViewGroupParamsOfWineMealBanner(viewGroup: ViewGroup, screenRatio: Float, hwRatio: Float) {
        val p = viewGroup.layoutParams
        p.width = ((ScreenUtils.getScreenWidth() - ScreenUtils.dpToPx(28) - ScreenUtils.dpToPx(11)) * screenRatio).toInt()
        p.height = (p.width * hwRatio).toInt()
        viewGroup.layoutParams = p
    }
    fun setViewGroupParamsOfWineMealBannerHeight(viewGroup: ViewGroup,screenRatio: Float, hwRatio: Float) {
        val p = viewGroup.layoutParams
        p.height = (((ScreenUtils.getScreenWidth() - ScreenUtils.dpToPx(28) - ScreenUtils.dpToPx(11)) * screenRatio) * hwRatio).toInt()
        viewGroup.layoutParams = p
    }
}